package cn.com.greatwall.file.service.impl;

import java.io.OutputStream;

import javax.annotation.Resource;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import cn.com.greatwall.oss.model.ObjectInfo;
import cn.com.greatwall.oss.properties.FileServerProperties;
import cn.com.greatwall.oss.template.FdfsTemplate;

/**
 * @Author herw
 * @Time 2022-02-19 19:50:44
 * @Version 1.0
 * @Description: TODO(用一句话描述该文件做什么)
 */
@Service
@ConditionalOnProperty(prefix = FileServerProperties.PREFIX, name = "type", havingValue = FileServerProperties.TYPE_FDFS)
public class FastdfsService extends AbstractIFileService {
    @Resource
    private FdfsTemplate fdfsTemplate;
    
    @Override
    public void out(String id, OutputStream os) {
    }

    @Override
    protected String fileType() {
        return FileServerProperties.TYPE_FDFS;
    }

    @Override
    protected ObjectInfo uploadFile(MultipartFile file) {
        return fdfsTemplate.upload(file);
    }

    @Override
    protected void deleteFile(String objectPath) {
        fdfsTemplate.delete(objectPath);
    }

}
